package com.test.designPattern.behaviorType.interpreterPattern;

/**
 * 工具类
 *
 * @author wangjie
 * @version V1.0
 * @date 2020/4/9
 */
public class OperatorUtil {


    public static Interpreter getExpressionObject(String s1, String s2, String symbol) {

        Interpreter firstExpression = new NumberInterpreter(s1);
        Interpreter secondExpression = new NumberInterpreter(s2);

        switch (symbol.hashCode()) {
            case 42:
                if (symbol.equals("*")) {
                    return new MultiInterpreter(firstExpression, secondExpression);
                }
                break;
            case 43:
                if (symbol.equals("+")) {
                    return new AddInterpreter(firstExpression, secondExpression);
                }
                break;
            case 45:
                if (symbol.equals("-")) {
                    return new ReduceInterpreter(firstExpression, secondExpression);
                }
                break;
            case 47:
                if (symbol.equals("/")) {
                    return new DivideInterpreter(firstExpression, secondExpression);
                }
        }
        return null;
    }
}
